<script setup lang="ts">
import { computed, defineComponent, onMounted, ref } from 'vue'
import { useRoute } from 'vue-router';
import { getArticlePage } from '../api/api';
const route = useRoute()
const data = ref([])
defineComponent({ name: 'RecentPost' })
const styleVars = computed(() => ({
    '--before-border-image': route.path.includes('detail')
        ? 'linear-gradient(90deg, transparent, #000) 1 1'
        : 'linear-gradient(90deg, transparent, #fff) 1 1',
    '--after-border-image': route.path.includes('detail')
        ? 'linear-gradient(90deg, transparent, #000) 1 1'
        : 'linear-gradient(90deg, transparent, #fff) 1 1'
}))

onMounted(() => {
    getArticlePage({
        pageNum: 1,
        pageSize: 10,
        tagIdList: [3]
    }).then(response => {
        data.value = response?.data?.records
    })
        .catch(error => {
            console.error('Error fetching data:', error);
        });

})
</script>

<template>
    <div class="page-layout-aside">
        <div class="latest-post">
            <div class="latest-post-title-wrap latest-post-title-wrap-light" :style="styleVars">
                <h2 class="latest-post-title" :style="{ color: route.path.includes('detail') ? '#000' : '#fff' }">RECENT
                    POSTS</h2>
            </div>
            <div class="latest-post-list">
                <div class="latest-post-item" v-for="(item, index) in data" :key="index">
                    <div class="vertical-news-card news-card news-card-light latest-post-item-card"
                        :style="{ background: route.path.includes('detail') ? '#fff' : '' }">
                        <div class="news-card-top "><a :href="`/detail/${item.id}`" class="news-card-img-link"><img
                                    :src="item?.image" alt="news image"></a></div>
                        <div class="news-card-bottom">
                            <p class="news-card-cnt"><a :href="`/detail/${item.id}`" :title="item?.title"
                                    class="ellipsis-2"
                                    :style="{ color: route.path.includes('detail') ? '#000' : '#fff' }">{{ item?.title
                                    }}</a>
                            </p>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
.page-layout-aside {
    display: none;
    width: 350px;

    .latest-post-title-wrap {
        position: relative;
        height: 28px;
        margin-bottom: 20px;
    }

    .latest-post-title-wrap-light:before,
    .latest-post-title-wrap-light:after {
        border-image: var(--before-border-image) !important;
    }

    .latest-post-title-wrap:before {
        left: 0;
    }

    .latest-post-title-wrap:after,
    .latest-post-title-wrap:before {
        position: absolute;
        top: 50%;
        transform: translate3d(0, -50%, 0);
        content: "";
        width: 90px;
        height: 0;
        border: 1px solid;
    }

    .latest-post-title {
        font-size: 20px;
        line-height: 28px;
        text-align: center;
        color: #fff;
    }


    .latest-post-title-wrap:after {
        right: 0;
        transform: translate3d(0, -50%, 0) rotate(180deg) !important;
    }



    .latest-post-list {
        .latest-post-item {
            margin-bottom: 18px;
        }

        .news-card {
            overflow: hidden;
            border-radius: 10px;
            transition: all .3s;
        }

        .news-card-top {
            overflow: hidden;
            cursor: pointer;
            opacity: 1;
            font-size: 0;
            transition: opacity .3s;
        }

        .news-card-light a {
            color: #fff;
        }

        .detail-page img {
            width: 100% !important;
            border-radius: 10px;
        }

        .vertical-news-card img {
            width: 100%;
            height: 200px;
        }

        .news-card-cnt {
            margin-bottom: 0;
            padding: 13px 11px;
        }

        .detail-page p {
            font-weight: 400;
            font-size: 16px;
            color: #fff;
            line-height: 22px;
            margin-bottom: 16px;
        }

        .news-card-light a {
            color: #fff;
            text-decoration: none;
        }

        .news-card-cnt a {
            color: #fff;
            font-size: 19px;
            line-height: 36px;
            font-weight: 700;
            text-align: left;
            word-break: break-all;
        }

        .ellipsis-2 {
            overflow: hidden;
            display: -webkit-box;
            text-overflow: ellipsis;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
        }
    }
}

@media screen and (min-width: 765px) {
    .page-layout-aside {
        display: block;
    }
}
</style>
